//
//  LPActivityResouceFileTableViewCell.m
//  ShangHaiHuDongApp
//
//  Created by 刘应平 on 2017/7/11.
//  Copyright © 2017年 刘应平. All rights reserved.
//

#import "LPActivityResouceFileTableViewCell.h"
#import "LPActDetailResouceTableViewCell.h"
#import "LPTentlyLeftLabelView.h"
#import "LPActivityDetailTableFooterView.h"
#define DETAILRESOUCE @"detailResouce"

@interface LPActivityResouceFileTableViewCell ()<UITableViewDelegate,UITableViewDataSource,LPActivityDetailFooterDelegate>
/**  table  */
@property (strong, nonatomic) UITableView  *tableView;

@end
@implementation LPActivityResouceFileTableViewCell

- (void)awakeFromNib {
    [super awakeFromNib];
    // Initialization code
}

- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
    [super setSelected:selected animated:animated];

    // Configure the view for the selected state
}


- (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier
{
    self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
    if (self) {
        self.selectionStyle = UITableViewCellSelectionStyleNone;
        [self layoutUI];
        
    }
    return self;
}

- (void)setDataArray:(NSArray *)dataArray{
    _dataArray = dataArray;
    CGFloat height = 0.0;
    if (dataArray.count != 0) {
        height = dataArray.count * 50 * [UIScreen zj_screenHScale] + 100 * [UIScreen zj_screenHScale];
        [self addHeaderAndFooter];
        CGRect frame = self.tableView.frame;
        frame.size.height = height;
        self.tableView.frame = frame;
        [self.tableView reloadData];
    }
}

/**  添加头部视图和尾部视图  */
- (void)addHeaderAndFooter{
    LPTentlyLeftLabelView *header = [[LPTentlyLeftLabelView alloc] initWithFrame:CGRectMake(0, 0, [UIScreen zj_screenWith], 40 * [UIScreen zj_screenHScale]) title:@"活动资源"];
    self.tableView.tableHeaderView = header;
    LPActivityDetailTableFooterView *footer = [[LPActivityDetailTableFooterView alloc] initWithFrame:CGRectMake(0, 0, [UIScreen zj_screenHScale], 60 * [UIScreen zj_screenHScale])];
    footer.delegate = self;
    footer.titles = @[@"查看更多资源"];
    self.tableView.tableFooterView = footer;
    
}

#pragma mark - LPActivityDetailFooterDelegate
- (void)lpActivityFooter_clickButton_index:(NSInteger)index{
    if (self.delegate) {
        [self.delegate LPActivityResouceFileTabelWithCell_watchMore:YES];
    }
}


#pragma mark - 界面
- (void)layoutUI{
    [self addSubview:self.tableView];
    
}



#pragma mark - UITableViewDataSource,UITableViewDelegate
/**  返回组个数  */
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView {
    return 1;
}
/**  返回cell个数  */
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
    return self.dataArray.count;
}
/**  返回cell高度  */
- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath {
    return 50 * [UIScreen zj_screenHScale];
}
/**  cell初始化  */
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
   
    LPActDetailResouceTableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:DETAILRESOUCE forIndexPath:indexPath];
    cell.model = self.dataArray[indexPath.row];
    return cell;
}
/**  cell的点击事件  */
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
    if (self.delegate) {
        [self.delegate LPActivityResouceFileTabelWithCell_index:indexPath.row];
    }
}

#pragma mark - 懒加载
/**  初始化tableView  */
- (UITableView *)tableView{
    if (!_tableView) {
        _tableView = [[UITableView alloc] initWithFrame:CGRectMake(0, 0, [UIScreen zj_screenWith], 110 * [UIScreen zj_screenHScale]) style:UITableViewStylePlain];
        _tableView.dataSource = self;
        _tableView.delegate = self;
        _tableView.separatorColor = [UIColor clearColor];
        _tableView.scrollEnabled = NO;
        _tableView.backgroundColor = [UIColor whiteColor];
        [_tableView registerClass:[LPActDetailResouceTableViewCell class] forCellReuseIdentifier:DETAILRESOUCE];
    }
    return _tableView;
}



@end
